//
//  WBOauthViewController.swift
//  weibo
//
//  Created by HanXujie on 2017/4/23.
//  Copyright © 2017年 thinker. All rights reserved.
//

import UIKit


/// 通过webView 加载新浪微博授权页面控制器
class WBOauthViewController: UIViewController {

    fileprivate lazy var webView = UIWebView()
    
    
    
    /// 重写loadview更换根视图
    override func loadView() {
        view = webView
        view.backgroundColor = UIColor.white
        
        // 设置导航栏
        title = "登录新浪微博"
        // 设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", target: self, action: #selector(close), isBackButton: true)
        
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        //MARK: -  加载授权页面
        // 设置URL
        let urlString = "https://api.weibo.com/oauth2/authorize?client_id=\(WBAppKey)&redirect_uri=\(WBRedirectURL)"
        
        // 确定URL没有问题
        guard let url = URL(string:urlString) else {
            return
        }
        
        // 建立请求
        let request = URLRequest(url: url)
        
        // 加载请求
        webView.loadRequest(request)
        
        
        
    }
    
    @objc fileprivate func close() {
        
        dismiss(animated: true, completion: nil)
    }



}
